package com.fz.controller.system;

import cn.hutool.core.convert.Convert;
import com.fz.aop.login.AnonymousAccess;
import com.fz.common.ResponseEntity;
import com.fz.beans.IdBeans;
import com.fz.beans.PageBeans;
import com.fz.dto.system.area.AreaAdd;
import com.fz.dto.system.area.AreaQuery;
import com.fz.dto.system.area.AreaUpd;
import com.fz.service.system.AreaService;
import com.fz.vo.system.area.AreaTreeVo;
import com.fz.vo.system.area.AreaVo;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author : xumj
 * @date : 2021/3/23 10:08
 */
@RestController
@Api(value = "地区管理", tags = "地区管理")
@RequestMapping("/area")
@CrossOrigin
@ApiSort(value = 7)
@SuppressWarnings("unchecked")
public class AreaController {

    @Resource
    private AreaService areaService;


    @GetMapping("/findAreaList")
    @ApiOperation(value = "查询地区分页列表")
    @ApiOperationSupport(order = 1)
    @AnonymousAccess
    public ResponseEntity<AreaVo> findAreaList(AreaQuery areaQuery,PageBeans pageBeans) throws Exception {
        return areaService.findAreaList(pageBeans.getPageNum(), pageBeans.getPageSize(), areaQuery);
    }

    @GetMapping("/findAreaTree")
    @ApiOperation(value = "查询地区树形结构图")
    @ApiOperationSupport(order = 2)
    public ResponseEntity<AreaTreeVo> findAreaTree() {
        return areaService.findAreaTree();
    }

    @GetMapping("/selectAreaList")
    @ApiOperation(value = "查询地区列表")
    @ApiOperationSupport(order = 3)
    public ResponseEntity<AreaVo> selectAreasList(AreaQuery areaQuery) {
        return areaService.selectAreasList(areaQuery);
    }

    @PostMapping("/saveArea")
    @ApiOperation(value = "新增地区")
    @ApiOperationSupport(order = 4)
    public ResponseEntity saveArea(@RequestBody AreaAdd areaAdd) throws Exception {
        return areaService.saveArea(areaAdd);
    }

    @PostMapping("/updateArea")
    @ApiOperation(value = "修改地区")
    @ApiOperationSupport(order = 5)
    public ResponseEntity updateArea(@RequestBody AreaUpd areaUpd) throws Exception {
        return areaService.updateArea(areaUpd);
    }

    @PostMapping("/delArea")
    @ApiOperation(value = "删除地区")
    @ApiOperationSupport(order = 6)
    public ResponseEntity delArea(@RequestBody IdBeans idBeans) throws Exception {
        Integer[] integers = Convert.toIntArray(idBeans.getIds());
        return areaService.delArea(integers);
    }

}
